package rabbitmq

import (
	"fmt"
	cfg "github.com/ufoscout/go-up"
)

func GetRabbitConsumerConfig(conf cfg.GoUp, configName string) (Exchange, Queue, BindingOptions, ConsumerOptions) {
	//fmt.Println(fmt.Sprintf("rabbitmq.consumer.%s.exchange", configName))
	//fmt.Println(conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange", configName)))
	//fmt.Println(conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange_type", configName)))
	//fmt.Println(conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.queue", configName)))
	//fmt.Println(conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.route_key", configName)))
	//fmt.Println(conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.tag", configName)))

	exchange := Exchange{
		Name:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange", configName)),
		Type:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange_type", configName)),
		Durable:    true,
		AutoDelete: false,
		Internal:   false,
		NoWait:     false,
		Args:       nil,
	}
	queue := Queue{
		Name:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.queue", configName)),
		Durable:    true,
		AutoDelete: false,
		Exclusive:  false,
		NoWait:     false,
		Args:       nil,
	}
	binds := BindingOptions{
		RoutingKey: conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.route_key", configName)),
		NoWait:     false,
		Args:       nil,
	}
	consumerOpts := ConsumerOptions{
		Tag:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.tag", configName)),
		AutoAck:   false,
		Exclusive: false,
		NoLocal:   false,
		NoWait:    false,
		Args:      nil,
	}
	return exchange, queue, binds, consumerOpts
}

func GetRabbitProducerConfig(conf cfg.GoUp, configName string) (Exchange, Queue, PublishingOptions) {
	exchange := Exchange{
		Name:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange", configName)),
		Type:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.exchange_type", configName)),
		Durable:    true,
		AutoDelete: false,
		Internal:   false,
		NoWait:     false,
		Args:       nil,
	}
	queue := Queue{
		Name:       conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.queue", configName)),
		Durable:    true,
		AutoDelete: false,
		Exclusive:  false,
		NoWait:     false,
		Args:       nil,
	}

	opts := PublishingOptions{
		RoutingKey: conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.route_key", configName)),
		Tag:        conf.GetString(fmt.Sprintf("rabbitmq.consumer.%s.tag", configName)),
		Mandatory:  false,
		Immediate:  false,
	}
	return exchange, queue, opts
}
